package com.yangdada.utils;



import com.yangdada.dto.PublicDataDTO;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * ykl
 * 2022/7/20
 */
public class DateReplenishUtil {


    public static  <T> List<T> dateReplenish(Map<String, T> map, T t, String state, String end) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date stateTime = simpleDateFormat.parse(state);
        Date endTime = simpleDateFormat.parse(end);

        List<T> list = new ArrayList<T>();
        int days = (int) ((endTime.getTime() - stateTime.getTime()) / (1000 * 3600 * 24));
        days = ~(days - 1);
        for (int i = 0; i >= days; i--) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(endTime);
            calendar.add(Calendar.DAY_OF_MONTH, i);
            String dayTime = simpleDateFormat.format(calendar.getTime());
            if (map.get(dayTime) == null){
                newObject(list, t, dayTime);
            }else {
                list.add(map.get(dayTime));
            }
        }
        return list;
    }

    public static  <T> List<T> dateReplenish(Map<String, T> map, T t) throws Exception {
        List<T> list = new ArrayList<T>();
        for (int i = 0; i <= 23; i++) {
            String date = "";
            if (i < 10){
                date = "0" + i;
            }else {
                date = String.valueOf(i);
            }
            if (map.get(date) == null){
                newObject(list, t,date);
            }else {
                list.add(map.get(date));
            }
        }
        return list;
    }

    public static <T> void newObject(List<T> list, T t, String date){
        if (t instanceof PublicDataDTO) {
            PublicDataDTO groupDealDataListVo = new PublicDataDTO();
            groupDealDataListVo.setDate(date);
            list.add((T) groupDealDataListVo);
        }
//        }else if (t instanceof GroupDealIncomeDataListVo){
//            GroupDealIncomeDataListVo groupDealIncomeDataListVo = new GroupDealIncomeDataListVo();
//            groupDealIncomeDataListVo.setDate(date);
//            list.add((T) groupDealIncomeDataListVo);
//        }else if (t instanceof GroupDealExpendDataListVo){
//            GroupDealExpendDataListVo groupDealExpendDataListVo = new GroupDealExpendDataListVo();
//            groupDealExpendDataListVo.setDate(date);
//            list.add((T) groupDealExpendDataListVo);
//        }
    }

}
